home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / readline-2.0mg.tar.gz / readline-2.0mg.tar / readline-2.0mg / history.h < prev    next >
C/C++ Source or Header  |  1994-08-03  |  7KB  |  181 lines

  1. /* History.h -- the names of functions that you can call in history. */
  2.  
  3. /* The structure used to store a history entry. */
  4. typedef struct _hist_entry {
  5.   char *line;
  6.   char *data;
  7. } HIST_ENTRY;
  8.  
  9. /* A structure used to pass the current state of the history stuff around. */
  10. typedef struct _hist_state {
  11.   HIST_ENTRY **entries;        /* Pointer to the entries themselves. */
  12.   int offset;            /* The location pointer within this array. */
  13.   int length;            /* Number of elements within this array. */
  14.   int size;            /* Number of slots allocated to this array. */
  15.   int flags;
  16. } HISTORY_STATE;
  17.  
  18. /* Flag values for the `flags' member of HISTORY_STATE. */
  19. #define HS_STIFLED    0x01
  20.  
  21. /* Initialization and state management. */
  22.  
  23. /* Begin a session in which the history functions might be used.  This
  24.    just initializes the interactive variables. */
  25. extern void using_history ();
  26.  
  27. /* Return the current HISTORY_STATE of the history. */
  28. extern HISTORY_STATE *history_get_history_state ();
  29.  
  30. /* Set the state of the current history array to STATE. */
  31. extern void history_set_history_state ();
  32.  
  33. /* Manage the history list. */
  34.  
  35. /* Place STRING at the end of the history list.
  36.    The associated data field (if any) is set to NULL. */
  37. extern void add_history ();
  38.  
  39. /* A reasonably useless function, only here for completeness.  WHICH
  40.    is the magic number that tells us which element to delete.  The
  41.    elements are numbered from 0. */
  42. extern HIST_ENTRY *remove_history ();
  43.  
  44. /* Make the history entry at WHICH have LINE and DATA.  This returns
  45.    the old entry so you can dispose of the data.  In the case of an
  46.    invalid WHICH, a NULL pointer is returned. */
  47. extern HIST_ENTRY *replace_history_entry ();
  48.  
  49. /* Stifle the history list, remembering only MAX number of entries. */
  50. extern void stifle_history ();
  51.  
  52. /* Stop stifling the history.  This returns the previous amount the
  53.    history was stifled by.  The value is positive if the history was
  54.    stifled, negative if it wasn't. */
  55. extern int unstifle_history ();
  56.  
  57. /* Return 1 if the history is stifled, 0 if it is not. */
  58. extern int history_is_stifled ();
  59.  
  60. /* Information about the history list. */
  61.  
  62. /* Return a NULL terminated array of HIST_ENTRY which is the current input
  63.    history.  Element 0 of this list is the beginning of time.  If there
  64.    is no history, return NULL. */
  65. extern HIST_ENTRY **history_list ();
  66.  
  67. /* Returns the number which says what history element we are now
  68.    looking at.  */
  69. extern int where_history ();
  70.   
  71. /* Return the history entry at the current position, as determined by
  72.    history_offset.  If there is no entry there, return a NULL pointer. */
  73. HIST_ENTRY *current_history ();
  74.  
  75. /* Return the history entry which is logically at OFFSET in the history
  76.    array.  OFFSET is relative to history_base. */
  77. extern HIST_ENTRY *history_get ();
  78.  
  79. /* Return the number of bytes that the primary history entries are using.
  80.    This just adds up the lengths of the_history->lines. */
  81. extern int history_total_bytes ();
  82.  
  83. /* Moving around the history list. */
  84.  
  85. /* Set the position in the history list to POS. */
  86. int history_set_pos ();
  87.  
  88. /* Back up history_offset to the previous history entry, and return
  89.    a pointer to that entry.  If there is no previous entry, return
  90.    a NULL pointer. */
  91. extern HIST_ENTRY *previous_history ();
  92.  
  93. /* Move history_offset forward to the next item in the input_history,
  94.    and return the a pointer to that entry.  If there is no next entry,
  95.    return a NULL pointer. */
  96. extern HIST_ENTRY *next_history ();
  97.  
  98. /* Searching the history list. */
  99.  
  100. /* Search the history for STRING, starting at history_offset.
  101.    If DIRECTION < 0, then the search is through previous entries,
  102.    else through subsequent.  If the string is found, then
  103.    current_history () is the history entry, and the value of this function
  104.    is the offset in the line of that history entry that the string was
  105.    found in.  Otherwise, nothing is changed, and a -1 is returned. */
  106. extern int history_search ();
  107.  
  108. extern int history_search_prefix ();
  109. /* Search the history for @var{string}, starting at history_offset.
  110.    The search is anchored: matching lines must begin with string. */
  111. /* Search for STRING in the history list, starting at POS, an
  112.    absolute index into the list.  DIR, if negative, says to search
  113.    backwards from POS, else forwards.
  114.    Returns the absolute index of the history element where STRING
  115.    was found, or -1 otherwise. */
  116. extern int history_search_pos ();
  117.  
  118. /* Managing the history file. */
  119.  
  120. /* Add the contents of FILENAME to the history list, a line at a time.
  121.    If FILENAME is NULL, then read from ~/.history.  Returns 0 if
  122.    successful, or errno if not. */
  123. extern int read_history ();
  124.  
  125. /* Read a range of lines from FILENAME, adding them to the history list.
  126.    Start reading at the FROM'th line and end at the TO'th.  If FROM
  127.    is zero, start at the beginning.  If TO is less than FROM, read
  128.    until the end of the file.  If FILENAME is NULL, then read from
  129.    ~/.history.  Returns 0 if successful, or errno if not. */
  130. extern int read_history_range ();
  131.  
  132. /* Write the current history to FILENAME.  If FILENAME is NULL,
  133.    then write the history list to ~/.history.  Values returned
  134.    are as in read_history ().  */
  135. extern int write_history ();
  136.  
  137. /* Append NELEMENT entries to FILENAME.  The entries appended are from
  138.    the end of the list minus NELEMENTs up to the end of the list. */
  139. int append_history ();
  140.  
  141. /* Truncate the history file, leaving only the last NLINES lines. */
  142. extern int history_truncate_file ();
  143.  
  144. /* History expansion. */
  145.  
  146. /* Expand the string STRING, placing the result into OUTPUT, a pointer
  147.    to a string.  Returns:
  148.  
  149.    0) If no expansions took place (or, if the only change in
  150.       the text was the de-slashifying of the history expansion
  151.       character)
  152.    1) If expansions did take place
  153.   -1) If there was an error in expansion.
  154.    2) If the returned line should just be printed.
  155.  
  156.   If an error ocurred in expansion, then OUTPUT contains a descriptive
  157.   error message. */
  158. extern int history_expand ();
  159.  
  160. /* Extract a string segment consisting of the FIRST through LAST
  161.    arguments present in STRING.  Arguments are broken up as in
  162.    the shell. */
  163. extern char *history_arg_extract ();
  164.  
  165. /* Return the text of the history event beginning at the current
  166.    offset into STRING. */
  167. extern char *get_history_event ();
  168.  
  169. /* Return an array of tokens, much as the shell might.  The tokens are
  170.    parsed out of STRING. */
  171. extern char **history_tokenize ();
  172.  
  173. /* Exported history variables. */
  174. extern int history_base;
  175. extern int history_length;
  176. extern int max_input_history;
  177. extern char history_expansion_char;
  178. extern char history_subst_char;
  179. extern char history_comment_char;
  180. extern char *history_no_expand_chars;
  181.